package com.heima.article.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.article.dto.ArticleDto;
import com.heima.article.dto.ArticleHomeDto;
import com.heima.article.dto.ArticleInfoDto;
import com.heima.article.entity.ApArticle;
import com.heima.article.mapper.ApArticleMapper;
import com.heima.article.service.IApArticleContentService;
import com.heima.article.service.IApArticleService;
import com.heima.common.dto.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 文章信息表，存储已发布的文章 服务实现类
 * </p>
 *
 * @author syl
 * @since 2023-04-19
 */
@Service
@Slf4j
// @Scope("singleton")  prototype  request  session globalSession
public class ApArticleServiceImpl extends ServiceImpl<ApArticleMapper, ApArticle> implements IApArticleService {

    @Autowired
    private IApArticleContentService apArticleContentService;
    // @Autowired
    //  private CreateHtmlTask createHtmlTask;


    @Autowired
    private StringRedisTemplate redisTemplate;

    private Integer computeScore(ApArticle article) {
        Integer score = 0;
        if (article.getViews() != null) {
            score += article.getViews() * 1;
        }

        if (article.getLikes() != null) {
            score += article.getLikes() * 3;
        }
        if (article.getComment() != null) {
            score += article.getComment() * 5;
        }
        if (article.getCollection() != null) {
            score += article.getCollection() * 8;
        }

        return score;

    }

    @Override
    public ResponseResult<Long> saveApArticle(ArticleDto dto) {
        return null;
    }

    @Override
    public ResponseResult load(ArticleHomeDto dto, int i) {
        return null;
    }

    @Override
    public ResponseResult loadArticleInfo(ArticleInfoDto dto) {
        return null;
    }

    @Override
    public void computeHotArticle() {

    }
}
